/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(function() {
        var a = audiojs.createAll({
        trackEnded: function() {
                // Per reproduir la seguent canço
                var next = $('ol li.playing').next();
                if (!next.length) next = $('ol li').first();
                next.addClass('playing').siblings().removeClass('playing');
                audio.load($('a', next).attr('data-src'));
                audio.play();
        }
        });
        // Per carregar e lprimer track al reproductor 
        var audio = a[0];
        first = $('ol a').attr('data-src');
        $('ol li').first().addClass('playing');
        audio.load(first);
        // Afegir una canço clicada a la llista
        $('ol li').click(function(e) {
            e.preventDefault();
            $(this).addClass('playing').siblings().removeClass('playing');
            audio.load($('a', this).attr('data-src'));
            audio.play();
        });
});

